package net.mihome.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

import net.mihome.app.R;
import net.mihome.app.adapter.MyFragmentAdapter;


/**
 * Created by ZHAO on 2014/12/29 0029.
 */
public class MainFragmentActivity extends FragmentActivity {
    // 账号在别处登录
    public boolean isConflict = false;
    ViewPager viewPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
            // 防止被T后，没点确定按钮然后按了home键，长期在后台又进app导致的crash
            // 三个fragment里加的判断同理
            finish();
            startActivity(new Intent(this, LoginActivity.class));
            return;
        }
        setContentView(R.layout.main_fragment);
        viewPager= (ViewPager) findViewById(R.id.viewpager_main);
        viewPager.setAdapter(new MyFragmentAdapter(getSupportFragmentManager()));
        viewPager.setCurrentItem(0);
        viewPager.setOffscreenPageLimit(3);// 设置缓存页面，当前页面的相邻N各页面都会被缓存
    }
}
